<template>
  <div>
    <el-table
      :data="tableData"
      border
      stripe
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="300">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="300">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="手机号"
        width="300">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="300">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        width="300">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建地址">
      </el-table-column>
    </el-table>
    <el-pagination
      background
      align="right"
      layout="prev, pager, next"
      :total="totals"
      :current-page="currentPage"
      :page-size="pageSize"
      @current-change="pageSwitch"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      totals:600,
      currentPage:1,
      pageSize:8,
    }
  },
  mounted() {
    //遍历出数据
    this.list()
  },
  methods:{
    pageSwitch(current){
      //再次点击其他页码时，列表数据和页码会一起改变
      this.currentPage = current;
      this.list()
    },
    list(){
      //发送axios请求
      this.$http.post("/dept/queryPage",{"currentPage":this.currentPage,"pageSize":this.pageSize})
      .then(result =>{
        //result.data获取的是后端的数据，至于具体的需要看返回的是哪个
        this.totals = result.data.totals;
        //tabledata是在data中取数据并渲染到前端
        this.tableData = result.data.rows
      })
      .catch(result =>{
        alert("我命由我不由天")
      })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
